﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Cms.Domain;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Cms.Tests.Unit.Domain
{

    [TestClass]
    public class SourceCodeTests
    {

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestAddVersion()
        {
            SourceCode sourceCode = new SourceCode();
            Assert.IsNull(sourceCode.CurrentVersion);
            Administrator admin = new Administrator {ID = 1};
            string code = "some code";
            sourceCode.AddVersion(code, admin);
            Assert.AreEqual(code, sourceCode.CurrentVersion.Code);
            Assert.AreEqual(admin.ID, sourceCode.CurrentVersion.EditedBy.ID);
            Assert.AreSame(sourceCode, sourceCode.CurrentVersion.Parent);
            code = "altered code";
            sourceCode.AddVersion(code, admin);
            Assert.AreEqual(code, sourceCode.CurrentVersion.Code);
            Assert.AreEqual(2, sourceCode.Versions.Count);
        }


        [TestMethod]
        public void TestCloneSourceCode()
        {
            Administrator admin = new Administrator();
            Site site = new Site { ID = 1 };
            SourceCode original = new SourceCode
            {
                ID = 1,
                Site = site
            };
            SourceCode clone = (SourceCode)original.Clone();
            Assert.AreEqual(0, clone.ID);
            Assert.IsNull(clone.CurrentVersion);
            original.AddVersion("some code", admin);
            original.AddVersion("altered code", admin);
            clone = (SourceCode)original.Clone();
            Assert.IsNotNull(clone.CurrentVersion);
            Assert.AreEqual(1, clone.Versions.Count);
            Assert.AreEqual("altered code", clone.CurrentVersion.Code);
        }

    }

}
